home *** CD-ROM | disk | FTP | other *** search
/ Screensavers 98 / Screensavers 98.iso / scr / pyro / fclasses.h < prev    next >
C/C++ Source or Header  |  2000-03-28  |  8KB  |  191 lines

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. // **** Fire work constants ****
  6. const int  Fixed = 10;            // Used in fixed point calculations.
  7. extern int MAXX, MAXY;
  8. extern int PixelSize;
  9.  
  10. // used int flare trailer to save previous points in a queue structure
  11. struct SaveXY
  12. {
  13.     int x, y;
  14. };
  15.  
  16. // ******* N.B. Fixed point addition can be optiomised *********
  17.  
  18. class Flare
  19. {
  20.    private:                                          
  21.             int      xPos, yPos;                       // start position of firework.
  22.             int      ground, cycles;                   // ground limit, and cycles of life for flare.
  23.             int      xPlot, yPlot;                     // X, Y increments for firework (fixed point).
  24.             int      gravConst, gravty, thrust;        // gravity pull on flare, virtical thrust on gravity, horizontal thrust
  25.             SaveXY*  trailer;                          // point to trailer queue structure
  26.             int      trailLen, bufPnt;                 // current size of trailer, current point in trailer element.
  27.             COLORREF colour;                           // current colour of flare.
  28.             BOOL     overBuf, alive;                   // over write trailer buffer, and determine in flare is still active.
  29.             BOOL     gndTerminated;                    // Test flare has hit the ground, if so then don't update x, y movement!
  30.  
  31.    protected:
  32.  
  33.             // Removes a point from the display, also adjust flooring of flare if
  34.             // it's below the floor limit. 
  35.             void removePoint (HDC hdc, int x, int y);
  36.  
  37.             // Displays a point from the display, also adjust flooring of flare if
  38.             // it's below the floor limit. 
  39.             void showPoint (HDC hdc, int x, int y);
  40.  
  41.    public:                                 
  42.            // ********* Constructors **********
  43.            Flare         (void);
  44.            Flare         (int  x,                  int      y,
  45.                           int thr = (1 * Fixed),  int     grav = (50 * Fixed),
  46.                           int  cyc = 20,           int      gnd  = MAXY,
  47.                           int  trailLength = 5,    COLORREF col  = RGB(255,255,255));
  48.  
  49.            // Setup a flare.
  50.            // x, y    :        Start location on the screen.
  51.            // thr     :        Horizontal pull of flare.
  52.            // gnd     :        Virtual pull of flare.
  53.            // cyc     :        Number of iterations of life (total life = cyc+trailLength).
  54.            // gnd     :        Set floor limit.
  55.            // trailLength:     Length of flare trail.
  56.            // col     :        Set colour of flare.
  57.            void  init    (int  x,                  int      y,
  58.                           int thr = (1 * Fixed),  int     grav = (50 * Fixed),
  59.                           int  cyc = 20,           int      gnd  = MAXY,
  60.                           int  trailLength = 5,    COLORREF col  = RGB(255,255,255));
  61.  
  62.            // This function will remove, move, and display a flare.
  63.            // hdc  :        handle to device context.
  64.            // returns true/false if flare is active.
  65.            BOOL  move     (HDC hdc);
  66.  
  67.            // Change color of flare.
  68.            void  setColour(COLORREF col)
  69.            {
  70.                 colour = col;
  71.            }
  72.  
  73.            // Get color of flare.
  74.            COLORREF getColour (void)
  75.            {
  76.                 return colour;
  77.            }
  78.  
  79.            int GetCycles (void)
  80.            {
  81.                 return cycles;
  82.            } 
  83.  
  84.            // Returns the current position of the flare 
  85.            void  getCurrentPos (int& x, int& y)
  86.                  {
  87.                     x = xPos + (xPlot / Fixed);
  88.                     y = yPos - (yPlot / Fixed);
  89.                  }
  90.  
  91.         // ********* Destructor **********
  92.         virtual  ~Flare   (void);
  93. };
  94.  
  95.  
  96. class SkyRocket
  97. {
  98.     private:
  99.             Flare    mainRocket;        // Main rocket object fire into the sky/screen
  100.             Flare*   pStarBurst;        // Pointer to an array of flare objects.
  101.             BOOL     explode;           // Variable used to determine if updating main rocket or explosion.
  102.             int      starBurstNum;      // Num of flares in explosion.
  103.             int      trailLen;          // Trailer len of explosions
  104.             COLORREF colour;            // Colour sky rocket.
  105.  
  106.             // Variables used to calculate the colour change during the
  107.             // life of flare!
  108.             int      colItemChange;     // R, G, B value to change
  109.             int      colChangeAmnt;     // Positive/Negative amount to change.
  110.  
  111.     public:
  112.            // **** constructor ****
  113.            SkyRocket ()
  114.            {
  115.                starBurstNum = 0;
  116.                pStarBurst   = NULL;
  117.                explode      = FALSE;
  118.            }
  119.  
  120.            // Setup a skyrocket.
  121.            // starBNum:        Number of objects in explosion. 
  122.            // x, y    :        Start location on the screen.
  123.            // thr     :        Horizontal pull of flare.
  124.            // gnd     :        Virtual pull of flare.
  125.            // cyc     :        Number of iterations of life (total life = cyc+trailLength).
  126.            // gnd     :        Set floor limit.
  127.            // trailLength:     Length of flare trail.
  128.            // col     :        Set colour of flare.
  129.            void init      (int  starBNum,
  130.                            int  x,                  int      y,
  131.                            int thr = (1 * Fixed),  int     grav = (50 * Fixed),
  132.                            int  cyc = 20,           int      gnd  = MAXY,
  133.                            int  trailLength = 5,    COLORREF col  = RGB(255,255,255));
  134.  
  135.            // This function will remove, move, and display a flare.
  136.            // hdc  :        handle to device context.
  137.            // returns true/false if flare is active.
  138.            BOOL move      (HDC hdc);
  139.  
  140.            // **** Destructor ****
  141.            ~SkyRocket()
  142.            {
  143.                 delete pStarBurst;
  144.            }
  145. };
  146.  
  147.  
  148. class FlowerPot
  149. {
  150.     private:
  151.             Flare*   pFlares;     // Point to flare object list.
  152.             int      flareNum;    // Flare number to allocate. 
  153.             COLORREF colour;      // Inital colour of flares.
  154.             int      cycles;      // Cycles of life for flower pot.
  155.             int      xPos, yPos;  // Inital x, y, pos of flower pot
  156.             int      trailLen;    // Trailer length variable.
  157.  
  158.             // Variables used to calculate the colour change during the
  159.             // life of flare!
  160.             int      colItemChange;     // R, G, B value to change
  161.             int      colChangeAmnt;     // Positive/Negative amount to change.
  162.  
  163.     public:
  164.            // **** constructor ****
  165.            FlowerPot ()
  166.            {
  167.                 pFlares = NULL;
  168.                 xPos = yPos = cycles = colour = flareNum = 0;
  169.            }
  170.  
  171.            // Initalise the flower pot.
  172.            // num       : Number of flares to display.
  173.            // x,y       : Start position of flower pot.
  174.            // col       : Colour of flower pot.
  175.            // cyc       : How long flower pot will live.
  176.            // tLen      : Trailer length
  177.            void init (int num, int x, int y, COLORREF col, int cyc, int tLen);
  178.  
  179.            // This function will remove, update, and display a flower pot.
  180.            // hdc  :        handle to device context.
  181.            // returns true/false if flare is active.
  182.            BOOL move (HDC hdc);
  183.  
  184.            // **** Destructor ****
  185.            ~FlowerPot()
  186.            {
  187.                 delete pFlares;
  188.            }
  189. };
  190.  
  191.